name: release

on:
  push:
    tags:
      - '*'

jobs:
  build_release:
    name: build_release
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v2
        with:
          fetch-depth: 0
      - name: Install toolchain
        run: |
          sudo apt update
          sudo apt --fix-missing install gcc-aarch64-linux-gnu iasl device-tree-compiler python3-pyelftools
      - name: version
        run: echo "::set-output name=version::$(echo $GITHUB_REF | cut -d / -f 3)"
        id: version
      - name: build artifact
        run: make release
      - name: release
        uses: actions/create-release@v1
        id: create_release
        with:
          draft: false
          prerelease: false
          release_name: ${{ steps.version.outputs.version }}
          tag_name: ${{ github.ref }}
          body_path: CHANGELOG.md
        env:
          GITHUB_TOKEN: ${{ github.token }}
      - name: upload QUARTZ64_EFI artifact
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ github.token }}
        with:
          upload_url: ${{ steps.create_release.outputs.upload_url }}
          asset_path: ./QUARTZ64_EFI.img.gz
          asset_name: QUARTZ64_EFI.img.gz
          asset_content_type: application/gzip
      - name: upload SOQUARTZ_EFI artifact
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ github.token }}
        with:
          upload_url: ${{ steps.create_release.outputs.upload_url }}
          asset_path: ./SOQUARTZ_EFI.img.gz
          asset_name: SOQUARTZ_EFI.img.gz
          asset_content_type: application/gzip
      - name: upload PINETAB2_EFI artifact
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ github.token }}
        with:
          upload_url: ${{ steps.create_release.outputs.upload_url }}
          asset_path: ./PINETAB2_EFI.img.gz
          asset_name: PINETAB2_EFI.img.gz
          asset_content_type: application/gzip
      - name: upload ROC-RK3566-PC_EFI artifact
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ github.token }}
        with:
          upload_url: ${{ steps.create_release.outputs.upload_url }}
          asset_path: ./ROC-RK3566-PC_EFI.img.gz
          asset_name: ROC-RK3566-PC_EFI.img.gz
          asset_content_type: application/gzip
      - name: upload ROC-RK3568-PC_EFI artifact
        uses: actions/upload-release-asset@v1
        env:
          GITHUB_TOKEN: ${{ github.token }}
        with:
          upload_url: ${{ steps.create_release.outputs.upload_url }}
          asset_path: ./ROC-RK3568-PC_EFI.img.gz
          asset_name: ROC-RK3568-PC_EFI.img.gz
          asset_content_type: application/gzip
